package cn.edu.gzist.chapter08.controller;

import cn.edu.gzist.chapter08.entity.User;
import cn.edu.gzist.chapter08.service.MessageProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private MessageProducerService messageProducerService;
    @RequestMapping("/user/{id}/{username}")
    public void psubPublisher(@PathVariable Integer id,@PathVariable String username) {
        User user=new User(id,username);
        messageProducerService.psubPublisher(user);
    }

    @RequestMapping("/user/{message}")
    public void routingPublisher(@PathVariable String message) {
        String[] m = message.split("&");
        messageProducerService.routingPublisher(m[0],m[1]);
    }
    @RequestMapping("/user/topic/{message}")
    public void topicPublisher(@PathVariable String message) {
        String[] m = message.split("&");
        messageProducerService.topicPublisher(m[0],m[1]);
    }
}